/**
 * Created by liaoweiping on 2016/12/26.
 * 我的报价--列表
 */
import React from 'react';
import {Link,hashHistory} from 'react-router';

import Headers from '../../components/qoute/Headers';
import TipsCommon from '../../components/qoute/TipsCommon';
import Global from '../../actions/Global';
var filemgt_server_url = Global.host;

//时间转化日期函数
function dateFun(time){
	var date=new Date(time),message,month,day;
		month=(date.getMonth()<9)?('0'+date.getMonth()):(date.getMonth()+1);
		day=(date.getDate()<10)?('0'+date.getDate()):date.getDate();
		message=date.getFullYear()+'-'+month+'-'+day;
		return message;
}

var QuoteBox=React.createClass({
    render: function() {
		var qoutelist;
		if(this.props.data==null){
			qoutelist=(
				<div className='qoute-nodata'>暂时没有报价信息</div>
			);
		}else if(this.props.data==''){
			qoutelist='';
		}else{
			qoutelist = this.props.data.map(function (qoute,index) {
				var me=dateFun(qoute.orderDate);
		      	return (
		      		<Link className={qoute.listpriceStatus=='C'?'qoute-box qoute-cancle':'qoute-box'} key={index} to={'quoteDetail/'+qoute.vendorListPriceId}>
			        	<h4><i>报价时间:</i>{me}</h4>
			        	<p><span>报价商品:</span>{qoute.goodsName}</p>
			        	<p><span>规格:</span>{qoute.goodsSpec}</p>
			        	<p><span>包装:</span>{qoute.goodsPacking}</p>
			        	<p><span>单价:</span>{qoute.buyPrice}</p>
			        	<p><span>供应量:</span>{qoute.orderQty}</p>
			        	<p><span>供应地区:</span>{qoute.supplyArea}</p>
			        	<div className='qouteImg'></div>
			       </Link>
		      	);
	   		});
		}

		return (
			<div className='qoute-content'>
				{qoutelist}
		    </div>
		);
    }
});

var QouteList = React.createClass({
	getInitialState: function() {
		return {
		  data:'',
		  commonShow:'none',//是否显示提示框
          commonContent:''//提示框内容
		};
    },
	componentDidMount: function() {
        //ajax请求我的报价列表接口
		var param = {
			vendorId:'1000000014',
			pageNo:1,
			pageSize:0
		};
		$.ajax({
			type: 'post',
			url: filemgt_server_url+'/purchase/queryListPrice',
			data: JSON.stringify(param),
			dataType: 'json',
			contentType:'application/json;charset=utf-8',
			success: function(data){
			    if(data.errorCode==0){
			    	if(data.data.length==0){
			    		this.setState({data:null});
				 		return false;
			    	}else{
			    		 this.setState({data:data.data});
			    	}
			    }else{
			    	this.setState({commonShow: 'block',commonContent:data.errorMsg});
				    setTimeout(function(){
						this.setState({ commonShow:'none',commonContent:''});
					}.bind(this),500);
			    }
			}.bind(this),
			error:function(){
				this.setState({commonShow: 'block',commonContent:'网络连接不上，请稍后再试'});
			    setTimeout(function(){
					this.setState({ commonShow:'none',commonContent:''});
				}.bind(this),500);
//			    this.setState({data:[{'supplyTime':'2012-12-12','goodsDesc':'苹果','goodsSpec':'5000mm','goodsPacking':'想装','buyPrice':'1000元/t','orderQty':'1000t','supplyArea':'中国大陆','listpriceStatus':'C','vendorListPriceId':'22'},{'supplyTime':'2012-12-12','goodsDesc':'苹果','goodsSpec':'5000mm','goodsPacking':'想装','buyPrice':'1000元/t','orderQty':'1000t','supplyArea':'中国大陆','listpriceStatus':'A','vendorListPriceId':'1'}]});
			}.bind(this)
		});
	},
 	render: function () {
	    return (
	       <div className='qoute-main'>
		        <Headers title='我的报价'/>
		        <QuoteBox data={this.state.data} />
		        <TipsCommon isShow={this.state.commonShow} content={this.state.commonContent}/>
	       </div>
	    )
  	}
});
export default QouteList;
